;;; +themes.el --- Summary -*- lexical-binding: t -*-

;; Author: p1uxtar
;; Maintainer: p1uxtar
;; Version: v1.0
;; Package-Requires: (custom themes Hesperus/Phosphorus)

;;; Commentary:

;; Switch (custom) themes.

;;; Code:

;; -------- fonts --------
(defun font-installed-p (font-name)
  "Check if font with FONT-NAME is available."
  (find-font (font-spec :name font-name)))
(when (display-graphic-p)
  (cl-loop for font in '("Cascadia Code" "SF Mono" "Source Code Pro"
                         "Fira Code" "Menlo" "Monaco" "Dejavu Sans Mono"
                         "Lucida Console" "Consolas" "SAS Monospace")
           when (font-installed-p font)
           return (set-face-attribute
                   'default nil
                   :font (font-spec :family font
                                    :weight 'normal
                                    :slant 'normal
                                    :size (cond ((eq system-type 'gnu/linux) 14.0)
                                                ((eq system-type 'windows-nt) 12.5)))))
  (cl-loop for font in '("Noto Color Emoji" "Segoe UI Emoji" "EmojiOne Color"
                         "Apple Color Emoji" "Symbola" "Symbol")
           when (font-installed-p font)
           return (set-fontset-font t 'unicode
                                    (font-spec :family font
                                               :size (cond ((eq system-type 'gnu/linux) 16.5)
                                                           ((eq system-type 'windows-nt) 15.0)))
                                    nil 'prepend))
  (cl-loop for font in '("-outline-思源黑体 CN-normal-normal-normal-sans-*-*-*-*-p-*-iso10646-1"
                         "-outline-微软雅黑 CN-normal-normal-normal-sans-*-*-*-*-p-*-iso10646-1"
                         "Source Han Sans CN" "Source Han Serif CN"
                         "WenQuanYi Micro Hei" "Microsoft Yahei UI" "Microsoft Yahei")
           when (font-installed-p font)
           return (set-fontset-font t '(#x4e00 . #x9fff)
                                    (font-spec :name font
                                               :weight 'normal
                                               :slant 'normal
                                               :size (cond ((eq system-type 'gnu/linux) 16.5)
                                                           ((eq system-type 'windows-nt) 15.0))))))

;; (fontset (#x4e00 . #x9fff)) can use charset name to instead
;; (dolist (charset '(han kana symbol cjk-misc bopomofo))
;;   (set-fontset-font
;;    (frame-parameter nil 'font)
;;    charset
;;    (font-spec :name font
;;               :weight 'normal
;;               :slant 'normal
;;               :size (cond ((eq system-type 'gnu/linux) 13.5)
;;                           ((eq system-type 'windows-nt) 15.0)))))

;; fonts specified method previously
;; (when (display-graphic-p)
;;   (set-face-attribute
;;    'default nil
;;    :font (font-spec :family "Source Code Pro"
;;                     :weight 'normal
;;                     :slant 'normal
;;                     :size 12.5))
;;   (set-fontset-font t 'unicode (font-spec :family "Segoe UI Emoji" :size 15))
;;   (dolist (charset '(han kana symbol cjk-misc bopomofo))
;;     (set-fontset-font
;;      (frame-parameter nil 'font)
;;      charset
;;      (font-spec :name "-outline-思源黑体 CN-normal-normal-normal-sans-*-*-*-*-p-*-iso10646-1"
;;                 :weight 'normal
;;                 :slant 'normal
;;                 :size 15.0))))

;; -------- switch between dark/light themes --------
(defun themes-switch-Hesperus ()
  "Switch themes to Hesperus."
  (interactive)
  (progn
    (disable-theme 'Phosphorus)
    (load-theme 'Hesperus t))
  ;; (when (display-graphic-p)
  ;;   (awesome-tray-mode 1))
  (when (eq system-type 'windows-nt)
    (p1uxtar-Win-frame-size)))

(defun themes-switch-Phosphorus ()
  "Switch themes to Phosphorus."
  (interactive)
  (progn
    (disable-theme 'Hesperus)
    (load-theme 'Phosphorus t))
  ;; (when (display-graphic-p)
  ;;   (awesome-tray-mode 1))
  (when (eq system-type 'windows-nt)
    (p1uxtar-Win-frame-size)))

(defun themes-switch-doom-dark ()
  "Switch to doom dark theme."
  (interactive)
  (progn
    (disable-theme 'doom-one-light)
    (load-theme 'doom-one t))
  (custom-set-faces
   '(font-lock-comment-face ((t (:slant italic))))
   '(font-lock-constant-face ((t (:weight semi-bold))))
   '(font-lock-keyword-face ((t (:weight semi-bold :slant italic))))
   '(org-table ((t :family "Source Code Pro"))))
  (when (featurep 'pyim)
    (setq curchg-default-cursor-color "gold"
          curchg-input-method-cursor-color "#e67e22")))
(global-set-key (kbd "C-c H") #'themes-switch-doom-dark)

(defun themes-switch-doom-light ()
  "Switch to doom light theme."
  (interactive)
  (progn
    (disable-theme 'doom-one)
    (load-theme 'doom-one-light t))
  (custom-set-faces
   '(font-lock-comment-face ((t (:slant italic))))
   '(font-lock-constant-face ((t (:weight semi-bold))))
   '(font-lock-doc-face ((t (:background "#efeae9")))) ;; #fdefca
   '(font-lock-keyword-face ((t (:weight semi-bold :slant italic))))
   '(font-lock-string-face ((t (:background "#ecf3ec")))) ;; #fdefca
   '(highlight ((t (:background "#c4e3ff" :foreground "#3D535A"))))
   ;; '(ivy-current-match ((t (:extend t :background "#b8b8b8"))))
   ;; '(ivy-posframe ((t (:background "#d4d4d4"))))
   '(org-table ((t :family "Source Code Pro"))))
  (when (featurep 'pyim)
    (setq curchg-default-cursor-color "#4078f2"
          curchg-input-method-cursor-color "#8d4bbb")))
(global-set-key (kbd "C-c P") #'themes-switch-doom-light)

(defun themes-switch-kaolin-dark ()
  "Switch to kaolin dark theme."
  (interactive)
  (progn
    (disable-theme 'kaolin-valley-light)
    (load-theme 'kaolin-dark t))
  ;; (custom-set-faces
  ;;  '(font-lock-comment-face ((t (:slant italic))))
  ;;  '(font-lock-constant-face ((t (:weight semi-bold))))
  ;;  '(font-lock-keyword-face ((t (:weight semi-bold :slant italic))))
  ;;  '(org-table ((t :family "Source Code Pro"))))
  ;; (when (featurep 'pyim)
  ;;   (setq curchg-default-cursor-color "gold"
  ;;         curchg-input-method-cursor-color "#e67e22"))
  )
(global-set-key (kbd "C-c H") #'themes-switch-kaolin-dark)

(defun themes-switch-kaolin-light ()
  "Switch to kaolin light theme."
  (interactive)
  (progn
    (disable-theme 'kaolin-dark)
    (load-theme 'kaolin-valley-light t))
  (custom-set-faces
   '(font-lock-comment-face ((t (:slant italic))))
   '(font-lock-constant-face ((t (:weight semi-bold))))
   ;; '(font-lock-doc-face ((t (:background "#efeae9")))) ;; #fdefca
   '(font-lock-keyword-face ((t (:weight semi-bold :slant italic))))
   '(font-lock-string-face ((t (:background "#F3DEBB")))) ;; #fdefca
   '(highlight ((t (:background "#EFB7FF" :foreground "#3D535A"))))
   ;; '(ivy-current-match ((t (:extend t :background "#b8b8b8"))))
   '(ivy-posframe ((t (:background "#F3E7D3"))))
   '(org-table ((t :family "Source Code Pro"))))
  (when (featurep 'pyim)
    (setq curchg-default-cursor-color "#4078f2"
          curchg-input-method-cursor-color "#8d4bbb")))
(global-set-key (kbd "C-c P") #'themes-switch-kaolin-light)

;; (when (eq system-type 'windows-nt)
;;   (p1uxtar-Win-frame-size))

;; ;; --------- switch themes --------
(cond
 ((eq system-type 'gnu/linux)
  (themes-switch-kaolin-dark))
 ((eq system-type 'windows-nt)
  (themes-switch-kaolin-light)))

;; path of (custom) themes
;; (add-to-list 'load-path (expand-file-name "themes" user-emacs-directory))


(provide '+themes)
;;; +themes.el ends here
